/**
 * @author dnk2
 */

function popitup(url) {
	newwindow=window.open(url,'name','height=500,width=750,scrollbars');
	if (window.focus) {newwindow.focus()}
	return false;
}



 //registration----------------------------------------------------------------------------

function register() {
	var name = document.getElementById("name").value ;
	var email = document.getElementById("email").value ;
	var pswd = document.getElementById("password").value ;
	var pswd2 = document.getElementById("password2").value ;
	
	var ethics = document.getElementById("consent").checked ;
	var rights = document.getElementById("rights").checked ;
	
	var status = document.getElementById("register_message") ;
	
	status.style.display = "none" ;
	
	if (name==null|| name=="") {
		status.innerHTML = "You must specifiy your name" ;
		status.style.display = "inline" ;
		return ;		
	}
	
	if (email==null|| email=="") {
		status.innerHTML = "You must specifiy a valid email address" ;
		status.style.display = "inline" ;
		return ;		
	}
	
	if (pswd==null|| pswd=="") {
		status.innerHTML = "You must specify a password" ;
		status.style.display = "inline" ;
		return ;
	}
	
	if (pswd2==null|| pswd2=="") {
		status.innerHTML = "You must confirm your password" ;
		status.style.display = "inline" ;
		return ;
	}
	
	if (pswd != pswd2) {
		status.innerHTML = "Your passwords are inconsistant" ;
		status.style.display = "inline" ;
		return ;
	}
	
	if (ethics != true) {
		status.innerHTML = "Your must read the ethical consent document" ;
		status.style.display = "inline" ;
		return ;
	}
	
	if (rights != true) {
		status.innerHTML = "Your must read the bill of rights" ;
		status.style.display = "inline" ;
		return ;
	}
	
	var parName = newElementAtt('param', '', new Array('name', 'value'), new Array('name', name) ) ;
	var parEmail = newElementAtt('param', '', new Array('name', 'value'), new Array('email', email) ) ;
	var parPswd = newElementAtt('param', '', new Array('name', 'value'), new Array('password', pswd) ) ;
		
	var paramList = newElement('paramList', parName + parEmail + parPswd);
  		 
  	var request = newElementAtt('request', paramList, new Array('lang', 'to', 'type', 'uid'), new Array('en',collection + '/Register', 'process', '1'  ) );
  	var message = newElement('message', request );
  	var soapMessage = messageToSOAP(message);
   
  	xmlHttp = XmlHttp.create();
  	xmlHttp.open("POST", "http://" + serverPath + "/services/localsite", true);
  	xmlHttp.onreadystatechange = new Function("processRegistrationResponse() ; ") ;
   
	xmlHttp.setRequestHeader("SOAPAction", "\"\"");
  	xmlHttp.setRequestHeader("Content-Type", "Content-Type: text/xml; charset=utf-8");
   
   	logDebug("Request: " + message) ;
   
  	xmlHttp.send(soapMessage);
	
}

function processRegistrationResponse() {
		
	if (this.xmlHttp.readyState == 4) {
		logDebug("Response: " + this.xmlHttp.responseXML.xml) ;
		
		var accept = this.xmlHttp.responseXML.getElementsByTagName('accept')[0];
		
		var message = document.getElementById("register_message") ;
   
   		if (accept != null) {
			var message = document.getElementById("register_message") ;
			message.innerHTML = "accepted!"
			message.style.display = "inline" ;
			
			var name = document.getElementById("name").value ;
			createCookie("koru_user", name, 1) ;
			
			//document.getElementById("navHome").click() ;
			window.location.href="index.htm" ;
			//window.location.reload() ;
		} else {
			var message = document.getElementById("register_message") ;
			message.innerHTML = this.xmlHttp.responseXML.xml ;
			message.style.display = "inline" ;
		}
	}
}
